<?php
/**
 * Created by PhpStorm.
 * User: ZCY
 * Date: 2018/12/28
 * Time: 19:19
 */
namespace api\controllers;
use common\event\data\MsgEvent;
use common\event\HandleEvent;
use yii\web\Controller;


class EventController extends Controller
{
    public $enableCsrfValidation = false;

    const EVENT_TEST1 = 'test1';
    const EVENT_TEST2 = 'test2';
    const EVENT_TEST3 = 'test3';

    public function init()
    {
        $this->on(self::EVENT_TEST1,function ($event){
            echo "hello,i am event1".$event->data.PHP_EOL;
        },'我被猪@了55555......');
        $this->on(self::EVENT_TEST2,[new HandleEvent(),'test2'],'我被猪@了55555......');
        $this->on(self::EVENT_TEST3,[new HandleEvent(),'test3'],'我被猪@了55555......');    //test3和test4 都订阅了TEST3事件
        $this->on(self::EVENT_TEST3,[new HandleEvent(),'test4'],'我被猪@了55555......');
    }


    public function actionTest1()
    {
        echo "hello event".PHP_EOL;
        $this->trigger(self::EVENT_TEST1);
        $this->trigger(self::EVENT_TEST2);
        $msgEvent = new MsgEvent();
        $msgEvent->title = 'event3';
        $this->trigger(self::EVENT_TEST3,$msgEvent);
    }




}